package com.study.七大原则.o6迪米特法则;

import java.util.ArrayList;
import java.util.List;

public class Demeter2 {

    public static void main(String[] args) {
        System.out.println("使用迪米特法则改进");
        //创建了一个schoolManager  对象
        SchoolManager schoolManager = new SchoolManager();
        //输出了学院员工id和学校总部员工id
        schoolManager.printAllEmployee(new CollegeManager() );
    }

    //学习总部员工
    static class Employee{
        private String id;


        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }
    }

    //学院的员工
    static class CollegeEmployee{
        private String id;


        public String getId() {

            return id;
        }

        public void setId(String id) {
            this.id = id;
        }
    }

    static class CollegeManager{
        //返回学院的所有员工
        public List<CollegeEmployee> getAllEmployee(){
            List<CollegeEmployee> list = new ArrayList<>();
            for (int i = 0; i < 10; i++) {
                CollegeEmployee emp = new CollegeEmployee();
                emp.setId("学院员工id="+i);
                list.add(emp);
            }
            return list;
        }

        //输出学院员工的信息
        public void printEmployee(){
            List<CollegeEmployee> allEmployee = this.getAllEmployee();
            System.out.println("---------分公司员工---------");
            for (CollegeEmployee collegeEmployee : allEmployee) {
                System.out.println(collegeEmployee.getId());
            }
        }
    }
    //学校的管理类
    //分析SchoolManager  的直接彭眼泪有哪些Employee、CollegeManager
    //CollegeEmployee不是直接朋友，违反了迪米特法则
    static class SchoolManager{
        //返回学校总部的员工
        public List<Employee> getAllEmployee(){
            ArrayList<Employee> list = new ArrayList<>();

            for (int i = 0; i <5 ; i++) {  //这里增加了5个员工
                Employee emp = new Employee();
                emp.setId("学校总部员工id="+i);
                list.add(emp);
            }
            return list;
        }
        void printAllEmployee(CollegeManager sub){

            //分析问题
            //1、将输出学院员工的方法封装到CollegeManager中
            sub.printEmployee();

            System.out.println("-------学校总部员工-------");
            List<Employee> allEmployee1 = this.getAllEmployee();
            for (Employee employee : allEmployee1) {
                System.out.println(employee.getId());
            }
        }
    }
}